#pragma once

#include "argument.h"

#define common_map(macro, ...) \
  __map_generate (common_args_length (__VA_ARGS__), macro, __VA_ARGS__)

#define __map_generate_1(macro, argument) \
  macro (argument)

#define __map_generate_2(macro, argument, ...) \
  macro (argument) __map_generate_1 (macro, __VA_ARGS__)

#define __map_generate_3(macro, argument, ...) \
  macro (argument) __map_generate_2 (macro, __VA_ARGS__)

#define __map_generate_4(macro, argument, ...) \
  macro (argument) __map_generate_3 (macro, __VA_ARGS__)

#define __map_generate_5(macro, argument, ...) \
  macro (argument) __map_generate_4 (macro, __VA_ARGS__)

#define __map_generate_6(macro, argument, ...) \
  macro (argument) __map_generate_5 (macro, __VA_ARGS__)

#define __map_generate_7(macro, argument, ...) \
  macro (argument) __map_generate_6 (macro, __VA_ARGS__)

#define __map_generate_8(macro, argument, ...) \
  macro (argument) __map_generate_7 (macro, __VA_ARGS__)

#define __map_generate_9(macro, argument, ...) \
  macro (argument) __map_generate_8 (macro, __VA_ARGS__)

#define __map_generate_10(macro, argument, ...) \
  macro (argument) __map_generate_9 (macro, __VA_ARGS__)

#define __map_generate_start(nargs, macro, ...) \
  __map_generate_##nargs (macro, __VA_ARGS__)

#define __map_generate(...) __map_generate_start (__VA_ARGS__)

#ifdef common_namespace

#define map(...) common_map (__VA_ARGS__)

#endif
